package com.supreme.studyserver.component;

import com.external.study.service.ImportFileService;
import com.supreme.studyserver.annotation.ProtoTypeBean;
import com.supreme.studyserver.entity.School;
import com.supreme.studyserver.entity.Student;
import com.supreme.studyserver.entity.Teacher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;

@Configuration
@Import(value = {ImportFileService.class})
public class StudentConfig {

    @Bean(value = "wangTeacher")
    @Lazy
    public Teacher teacher() {
        final Teacher teacher = new Teacher();
        teacher.setName("wang teacher");
        return teacher;
    }

    @Bean(value = "zhangTeacher")
    public Teacher zhangTeacher() {
        final Teacher teacher = new Teacher();
        teacher.setName("zhang teacher");
        return teacher;
    }

    @Bean(value = "liuTeacher")
    public Teacher liuTeacher() {
        final Teacher teacher = new Teacher();
        teacher.setName("liu teacher");
        return teacher;
    }

    @Bean(value = "chenTeacher")
    @Lazy
    public Teacher chenTeacher() {
        final Teacher teacher = new Teacher();
        teacher.setName("chen teacher");
        return teacher;
    }

    @Bean
    public Student student() {
        final Student student = new Student();
        student.setName("peter");
        student.setPoint(88);
        student.setTeacher(teacher());
        return student;
    }

    @Bean
    public Student alexStudent() {
        final Student student = new Student();
        student.setName("alex");
        student.setPoint(89);
        student.setTeacher(teacher());
        return student;
    }

    @Bean
    public Student chrisStudent(Teacher zhangTeacher) {
        final Student student = new Student();
        student.setName("chris");
        student.setPoint(95);
        student.setTeacher(zhangTeacher);
        return student;
    }

    @Bean(initMethod = "initSchool", destroyMethod = "destroySchool")
    @ProtoTypeBean
    public School school() {
        final School school = new School();
        school.setName("理工大学");
        return school;
    }
}
